/******************************************************************************/
/*!
	\file	SoundSystem.h
	\author	Jack Kern
	\date	03/28/2007

	\brief
	
	This file is the main interface file for the HighLevel sound system
	it provides a complete interface for controling the larmobile sound engine.

	\par	license
	All content (c) 2005, DigiPen (USA) Corporation, all rights reserved.
*/
/******************************************************************************/

#pragma once

#include <Windows.h>
#include "Handles.h"
#include "XMLDoc.h"
#include "AudioTypes.h"

namespace Audio
{
	class CoreSystem;
}

public __gc class ToolSystem
///////////////////////////////////////////////////////////////////////////////
// Description: The ToolSystem is purely an interface for the tool programmers
//				it is equivalent to the SoundSystem class
//
// Recent Changes:
// -brasmuss 4/10/2007 : Created
///////////////////////////////////////////////////////////////////////////////
{
public:
					ToolSystem() : m_core(0), m_xmlHandle(0) {}
	bool			Initialize( void* hwnd );					//!< Creates the low level engine
	void			Update(float delta);
	bool			Destroy();

	bool			LoadSoundXML(		const char* file );		//!< Set the sound XML file name that was created by the tool
	bool			SaveSoundXML(		const char* file );		//!< Save all the SoundSystem information to XML format
	void			Clear();

	// Sound file management
	FileHandle		NewSoundFile(		const char* name, const char* file );
	FileHandle		GetSoundFileHandle(	bool first );
	const char*		GetSoundFilename(	const FileHandle& handle );
	const char*		GetSoundName(		const FileHandle& handle );
	bool			SetSoundFilename(	const FileHandle& handle, const char* filename );
	bool			SetSoundName(		const FileHandle& handle, const char* name );
	bool			RemoveSound(		const FileHandle& handle );
	unsigned		GetSoundFreq(		const FileHandle& handle );
	unsigned		GetSoundBitDepth(	const FileHandle& handle );
	unsigned		GetSoundChannels(	const FileHandle& handle );
	int				GetSoundLength(		const FileHandle& handle );
	
	// Sound path management
	bool 			SetSoundPath(		const char* path );
	const char*		GetSoundPath();

	// Variable management
	VariableHandle	NewVariable(		const char* varName, float min, float max );
	VariableHandle	GetVariableHandle(	bool first );
	const char*		GetVariableName(	const VariableHandle& handle );
	float			GetVariableMin(		const VariableHandle& handle );
	float			GetVariableMax(		const VariableHandle& handle );
	float			GetVariableValue(	VariableHandle& handle );
	bool			SetVariableName(	const VariableHandle& handle, const char* name );
	bool			SetVariableMin(		const VariableHandle& handle, float min );
	bool			SetVariableMax(		const VariableHandle& handle, float max );
	bool			SetVariableValue(	const VariableHandle& handle, float value );
	bool			RemoveVariable(		const VariableHandle& handle );

	// Graph management
	GraphHandle		GetGraphHandle(		bool first );
	GraphHandle		NewGraph(			const char* graphName );
	bool			ClearGraph(			const GraphHandle& graphID );
	bool			RemoveGraph(		const GraphHandle& graphID );
	const char*		GetGraphName(		const GraphHandle& graphID );
	bool			SetGraphName(		const GraphHandle& graphID, const char* name );
	bool			AddPoint(			const GraphHandle& graphID, float x, float y);
	unsigned		GetPointCount(		const GraphHandle& graphID );
	float			GetPointX(			const GraphHandle& graphID, const unsigned index );
	float			GetPointY(			const GraphHandle& graphID, const unsigned index );
	
	// Events, SubEvents & Effects
	EventHandle		GetEventHandle(		bool first );
	EventHandle		NewEvent(			const char* name, bool looping );
	bool			RemoveEvent(		const EventHandle& eventID );
	SubEventHandle	AddSubEvent(		const EventHandle& eventID, const char* soundName, float triggerTime, int pitchShift, bool streaming );
	bool			RemoveSubEvent(		const EventHandle& eventID, const SubEventHandle& subID );
	EffectHandle	AddSoundEffect(		const EventHandle& eventID, const SubEventHandle& subID, const char* graphName, const char* varName,  unsigned effect );
	EffectHandle	AddSoundEffect(		const EventHandle& eventID, const SubEventHandle& subID, const GraphHandle& graphID, const VariableHandle& varID, unsigned effect );
	bool			RemoveSoundEffect(	const EventHandle& eventID, const SubEventHandle& subID, const EffectHandle& effect );
	const char*		GetEventName(		const EventHandle& eventID );
	bool			GetEventLooping(	const EventHandle& eventID );
	SubEventHandle	GetSubEventHandle(	const EventHandle& eventID, bool first );
	const char*		GetSoundName(		const EventHandle& eventID, const SubEventHandle& subID );
	float			GetTriggerTime(		const EventHandle& eventID, const SubEventHandle& subID );
	int				GetPitchShift(		const EventHandle& eventID, const SubEventHandle& subID );
	bool			GetStreaming(		const EventHandle& eventID, const SubEventHandle& subID );
	EffectHandle	GetEffectHandle(	const EventHandle& eventID, const SubEventHandle& subID, bool first );
	GraphHandle		GetEffectGraph(		const EventHandle& eventID, const SubEventHandle& subID, const EffectHandle& fxID );
	VariableHandle	GetEffectVariable(	const EventHandle& eventID, const SubEventHandle& subID, const EffectHandle& fxID );
	unsigned		GetEffectType(		const EventHandle& eventID, const SubEventHandle& subID, const EffectHandle& fxID );
	
private:
	XMLFileHandle			m_xmlHandle;
	Audio::CoreSystem*		m_core;		// Guaranteed to be valid during the lifetime of the ToolSystem
};
